package vashion.azeroth.core.manager.item;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import vashion.azeroth.core.dao.BaseDao;
import vashion.azeroth.core.item.dao.ItemDao;
import vashion.azeroth.core.item.pojo.ItemDO;
import vashion.azeroth.core.item.query.ItemQueryDO;
import vashion.azeroth.core.manager.impl.BaseManagerImpl;

import java.util.List;
import java.util.Map;

/**
 * Created by tingting on 15/8/31.
 * 基础的商品增删改查，其他模块不要用这个，要使用具体增强的read/write
 */
@Service
public class BaseItemManager extends BaseManagerImpl<ItemDO> {

    @Autowired
    private ItemDao itemDao;

    @Override
    public BaseDao getDao() {
        return itemDao;
    }

    public Long saveWithId(ItemDO itemDO) {

        return itemDao.saveWithId(itemDO);
    }

    /**
     * 此接口废弃，使用queryItem查询
     *
     * @param itemDO
     * @return
     */
    @Override
    public List<ItemDO> find(ItemDO itemDO) {
        return Lists.newArrayList();
    }
    
	@Override
	public List<ItemDO> findAll(ItemDO itemDO) {
		return itemDao.findAll(itemDO);
	}

    /**
     * 此接口废弃，使用countQueryItem查询
     *
     * @param itemDO
     * @return
     */
    @Override
    public int findCnt(ItemDO itemDO) {
        return 0;
    }

    public List<ItemDO> queryItem(ItemQueryDO itemQueryDO) {
        return itemDao.queryItem(itemQueryDO);
    }

    public List<ItemDO> querySameCodeItem(ItemQueryDO itemQueryDO) {
        return itemDao.querySameCodeItem(itemQueryDO);
    }

    public Integer countQueryItem(ItemQueryDO itemQueryDO) {
        return itemDao.countQueryItem(itemQueryDO);
    }

    public List<String> getRecommendTitle(String word) {
        return itemDao.getRecommendTitle(word);
    }

    /**
     * 更新商品的销量好库存
     *
     * @param itemId
     * @param updateSale
     * @param stockCount
     * @return
     */
    public boolean updateSkuAndSale(long itemId, int updateSale, int stockCount) {
        Map<String, Object> paramMap = Maps.newHashMap();
        paramMap.put("itemId", itemId);
        paramMap.put("updateSale", updateSale);
        paramMap.put("stockCount", stockCount);
        return itemDao.updateSkuAndSale(paramMap);
    }
}
